package com.jari.lg.service.profile.vehicle;

import com.jari.lg.domain.DevBase;
import com.jari.lg.domain.ScenicSpotCarDayEntity;
import com.jari.lg.mapper.ScenicSpotCarDayEntityMapper;
import com.jari.lg.utils.BaseData;
import com.jari.lg.utils.Constants;
import com.jari.lg.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ScenicSpotCarDayService {

    @Autowired
    private ScenicSpotCarDayEntityMapper scenicSpotCarDayEntityMapper;


    /*
    *  每天统计一次 每天产生一次数据
    * */
    public void makeInfo(){
        ScenicSpotCarDayEntity entity;
        List<DevBase> devBases = BaseData.checkpointList;
        for(DevBase devBase : devBases){
            entity = generate(devBase);
            scenicSpotCarDayEntityMapper.insert(entity);
        }
    }

    private ScenicSpotCarDayEntity generate(DevBase devBase){
        ScenicSpotCarDayEntity entity = new ScenicSpotCarDayEntity();
        entity.setCheckpointcode(devBase.getDevicecode());
        entity.setCheckpointname(devBase.getDevicename());
        entity.setCreator("SYS");
        entity.setDate(new Date());
        entity.setDatastatus(Constants.DATA_STATUS_ONE);
        entity.setLocalcarnum(Utils.CAR_NUM.get(Constants.LOCAL));
        entity.setNolocalcarnum(Utils.CAR_NUM.get(Constants.NO_LOCAL));
        entity.setPassingcarnum(entity.getLocalcarnum() + entity.getNolocalcarnum());
        return entity;
    }
}
